package com.tj.collection.task;

import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.kly.user.service.ChatterService;
import com.tj.collection.db.dao.ChatterWorkSettingDao;
import com.tj.collection.db.entity.ChatterWorkSettingEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * 推送排班时间任务
 */
@Service
public class ChatterWorkingSetTransferTask {

    private static Log logger = LogFactory.getLog(ChatterWorkingSetTransferTask.class);
    @Resource
    ChatterWorkSettingDao chatterWorkSettingDao;
    @Resource
    ChatterService chatterService;

    /**
     * 统计频率：3600s
     */
    @Scheduled(fixedDelay = 1000 * 3600)
    public void run() {
        final List<ChatterWorkSettingEntity> waitingTransferData = chatterWorkSettingDao.listWaitingTransferData();
        if (CollectionUtils.isEmpty(waitingTransferData)) {
            return;
        }
        for (ChatterWorkSettingEntity entity : waitingTransferData) {
            chatterService.updateChatterWorking(entity.getChatterCode(), entity.getStartHour(), entity.getEndHour(), entity.getStartHour2(), entity.getEndHour2());
            entity.setTransferFlag(1);
            chatterWorkSettingDao.updateByPrimaryKey(entity);
        }
    }

}
